package com.sporadic.backstage.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sporadic.backstage.entity.UserRank;
import com.sporadic.backstage.mapper.UserRankMapper;
import com.sporadic.backstage.service.UserRankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserRankServiceImpl implements UserRankService {
    @Autowired
    private UserRankMapper userRankMapper;

    /**
     * 查询商家积分等级列表
     * @param merchantId 商家编号
     * @return 等级集合
     */
    @Override
    public List<UserRank> selUserRankAll(Integer merchantId) {
       return userRankMapper.selUserRankAll(merchantId);
    }

    /**
     * 修改商家积分信息
     * @param userRank 积分信息 必要参数1.商家编号 2.要修改积分编号
     * @return 受影响的行数
     */
    @Override
    public Integer upUserRank(UserRank userRank) {
        QueryWrapper<UserRank> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("id",userRank.getId());
        queryWrapper.eq("user_rank_merchant",userRank.getUser_rank_merchant());
        return userRankMapper.update(userRank,queryWrapper);
    }

    /**
     * 删除商家积分信息
     * @param id 积分编号
     * @param merchantId 商家编号
     * @return 受影响的行数
     */
    @Override
    public Integer delUserRank(Integer id, Integer merchantId) {
        QueryWrapper<UserRank> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("id",id);
        queryWrapper.eq("user_rank_merchant",merchantId);
        return userRankMapper.delete(queryWrapper);
    }

    /**
     * 添加商家积分信息
     * @param userRank 积分信息
     * @return 受影响的行数
     */
    @Override
    public Integer addUserRank(UserRank userRank) {
        return userRankMapper.insert(userRank);
    }
}
